<?php
// 支持事先使用静态方法设置Request对象和Config对象
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Access-Control-Allow-Methods: GET, POST');
#获取服务器上的版本信息
$keyJson = @$_GET['key'];
$data = json_decode($keyJson, 1);
if(!$keyJson || !$data){
    echo json_encode([
        'code'    => 101,
        'result'  => [],
        'message' => "参数错误",
    ], JSON_UNESCAPED_UNICODE);
    exit();
}
$arr = [];
foreach($data as $key){
    $arr[$key] = 0;
       if($key=="ryb"){
        $versionPrefix="4.0.0";
    }else{
        $versionPrefix="3.0.0";
    }
    $path = dirname(dirname(__FILE__)) .  '/update/' . $key . '/'.$versionPrefix.'/';
    $path = strtr($path, DIRECTORY_SEPARATOR, '/');
    //获取全部的wgtu包
    $list = glob($path . '*.wgtu');
    rsort($list);
    if($list){
        $str = mb_substr($list[0], -14);
        $updateDate=date("Y-m-d",strtotime(mb_substr($str, 0, 8)));
        $arr[$key] = [
            "date" => $updateDate,
            "v"    => mb_substr($str, 8, 1),
        ];
    }
}
echo json_encode([
    'code'    => 200,
    'result'  =>$arr,
    'message' => "获取成功",
], JSON_UNESCAPED_UNICODE);
exit();
?>